package com.atguigu.gulimall.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName GulimallElasticsearchConfig
 * @Description TODO
 * @Detail  SpringBoot整合ES步骤
 *          1、导入elasticsearch-rest-high-level-client依赖
 *          2、创建一个配置类，注入RestHighLevelClient的bean
 *          3、测试一下是否注入成功
 * @Author MyPC
 * @Date 2020/6/15
 * @Version 1.0
 */

@Configuration
public class GulimallElasticsearchConfig {
    @Bean
    public RestHighLevelClient esRestClient(){
        RestClientBuilder builder=null;
        builder=RestClient.builder(new HttpHost("169.254.62.107",9200,"http"));
        return new RestHighLevelClient(builder);
    }
    //单例模式，所有请求共享
    public static final RequestOptions COMMON_OPTIONS;
    static {
        RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
//        builder.addHeader("Authorization", "Bearer " + TOKEN);
//        builder.setHttpAsyncResponseConsumerFactory(
//                new HttpAsyncResponseConsumerFactory
//                        .HeapBufferedResponseConsumerFactory(30 * 1024 * 1024 * 1024));
        COMMON_OPTIONS = builder.build();
    }
}
